﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PM.Web
{
    public partial class NewsClass : System.Web.UI.Page
    {
        public string Name = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData();
            }
        }

        private void bindData()
        {
            int cid = 0;
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                if (!int.TryParse(Request.QueryString["id"].Trim(), out cid))
                {
                    this.Name = "非法参数！";
                    return;
                }
            }
            
           
            DataAccess.PmData dal = new DataAccess.PmData();
            if (cid == 0)
                this.Name = "全部新闻";
            else
                this.Name = dal.GetWebSiteNewsClass(Common.GetCommunityCode(), cid).Rows[0]["Name"].ToString();
            System.Data.DataTable dt = dal.GetWebSiteNewsList(Common.GetCommunityCode(), cid, null, null);
            AspNetPager1.RecordCount = dt.Rows.Count;
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.DataSource = dt.DefaultView;
            this.repNewsList.DataSource = pds;
            this.repNewsList.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }
    }
}